package com.sky.controller.User;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("userSetmealController")
@RequestMapping("/user/setmeal")
@Slf4j
@Api(tags = "套餐")
public class SetmealController {
    @Autowired
    SetmealService setmealService;

    /**
     * @return 根据分类id查询指定分类下的套餐列表
     * @author 小陈
     * @Params:
     * @DateTime:
     * cacheNames = 缓存的名称，管理一组缓存的key
     *         unless = 满足条件，不进行缓存
     *         condition = 满足条件，才进行缓存
     */                                                                                    //套餐列表是null，不进行缓存
    @Cacheable(cacheNames = "setmealCache" , key ="'setmeal_'+#categoryId",unless = "#result.data.size()==0")
    @GetMapping("/list")
    public Result<List<Setmeal>> list(Long categoryId) {

        List<Setmeal> setmeals = setmealService.list(categoryId);
        return Result.success(setmeals);
    }

    /**
     * @return 根据套餐id查询包含的菜品
     * @author 小陈
     * @Params:
     * @DateTime:
     */
    @GetMapping("/dish/{id}")
    @ApiOperation("根据套餐id查询包含的菜品列表")
    public Result<List<DishItemVO>> dishList(@PathVariable Long id) {
        List<DishItemVO> list = setmealService.getDishItemById(id);
        return Result.success(list);
    }
}
